<!doctype html>
<html>
  <head>
    <title>Intent: Discover</title>
    <script src="/lib/webintents.debug.js"></script>
    <script src="/lib/events.js"></script>
    <script>
     attachEventListener(window, "load", function() {
        var selectAPI = document.getElementById("selectAPI");
        attachEventListener(selectAPI, "click", function() {
          var intent = new Intent();
          intent.action = "http://webintents.org/discover";
          intent.type = "application/JSON";

          window.navigator.startActivity(intent, intentResponse);

          return false;
        });
  
        var intentResponse = function (intentData) {
          var output = document.getElementById("output");
          var intentDesc;
          for(var i = 0; intentDesc = intentData.data[i]; i++) {
            var li = document.createElement("li");
            var a = document.createElement("a");
            a.innerText = intentDesc.title;
            a.href = intentDesc.action;
            a.target = "_blank";
            li.appendChild(a);
            output.appendChild(li);
          }
        };
      }, false);
    </script>  
  </head>
  <body>
    <h2>Discover API's</h2>
    <button id="selectAPI">Pick a Service</button>
    <h3>Response will appear here:</h3> 
    <ul id="output">

    </ul>

    <h3>Code</h3>
    <pre>var intent = new Intent();
intent.action = "http://webintents.org/discover";
intent.type = "application/JSON";

window.navigator.startActivity(intent, intentResponse);

var intentResponse = function (intentData) {
  var output = document.getElementById("output");
  var intentDesc;
  for(var i = 0; intentDesc = intentData[i]; i++) {
    var li = document.createElement("li");
    var a = document.createElement("a");
    a.innerText = intentDesc.title;
    a.href = intentDesc.action;
    a.target = "_blank";
    li.appendChild(a);
    output.appendChild(li);
  }
};</pre>
  </body>
</html>

